﻿using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using NLog;
using NLog.Web;

namespace OrderingFoot.Core
{
    /// <summary>
    /// LogExtension
    /// </summary>
    public static class LogExtension
    {
        /// <summary>
        /// log
        /// </summary>
        public static void UseLog<TProgram>(this IHostBuilder hostBuilder, ILoggingBuilder loggingBuilder, string logdir = null)
        {
            LogManager.Setup().LoadConfigurationFromAppSettings().GetCurrentClassLogger();
            LogManager.Configuration.Variables["logdir"] = logdir ?? Path.GetDirectoryName(typeof(TProgram).Assembly.Location);
            loggingBuilder.ClearProviders();
            loggingBuilder.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
            hostBuilder.UseNLog();
        }
    }
}
